package org.bolmart.custservice;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//import org.apache.commons.logging.Log;
//import org.apache.commons.logging.LogFactory;

import org.bolmart.dao.*;

import java.util.List;

import java.io.IOException;
import java.util.ArrayList;

public class MainController implements Controller {

	//protected final Log logger = LogFactory.getLog(getClass());

	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		Resource resource = new FileSystemResource(
				"C:/Users/Boris/workspace/org.bolmart.custservice/WebContent/WEB-INF/custservice-servlet.xml");
		BeanFactory factory = new XmlBeanFactory(resource);

		Customer user = new Customer();

		UsersDao usersDao = (UsersDao) factory.getBean("usersDao");
		// UsersDao.saveOrUpdate(user);

//		Foo foo = new Foo();
//		List<Customer> ll = new ArrayList<Customer>();
//		ll = foo.getCustomer();
//		Customer customer = ll.get(1);
		
		
		Customer customer = UsersDao.getCustomer(1);
		String now = customer.getLastName();
//		//logger.info("Returning hello view");
		return new ModelAndView("helloBoris", "now", customer);
//		return new ModelAndView("helloBoris.jsp");
		
		
	}

}